<?php include_once 'top.php' ;?>
<?php
	$action=$_REQUEST['action'];
	switch($action){
	    case 'add':
		$sql="insert into account (title, price) values ('".$_POST['title']."','".$_POST['price']."')";
		mysql_query($sql) or die(mysql_error().'<br>'.$sql);
		alert('Add success');
		gourl('account.php');
		break;
		
		case 'edit':
		$id=$_REQUEST['id'];
		$sql="update account set title='".$_POST['title']."',price='".$_POST['price']."' where id=$id";
		mysql_query($sql) or die(mysql_error().'<br>'.$sql);
		alert('Modify success');
		gourl('account.php');
		break;
		
		case 'del':
		$id=$_REQUEST['id'];
		$sql = "delete from account where id=$id";
		mysql_query($sql) or die(mysql_error().'<br>'.$sql);
		alert('Deleted successful');
		gourl('account.php');
		break;
		
		case 'delall':
		if(count($_POST['checkid'])!=0){
		$del = implode(',', $_POST['checkid']);
		$sql = "delete from account where id in ($del)";
		mysql_query($sql) or die(mysql_error().'<br>'.$sql);
		}
		alert('Batch successful deleted');
		gourl('account.php');
		break;
	}
?>
<div class="centerbg">
  <div class="allbody">
    <div class="bd">
      <div class="nytitle">
        <div class="fl title">account</div>
        <div class="fr"><a class="nybutton" href="javascript:show_window('account','');">ADD&nbsp;account</a></div>
        <div class="clear"></div>
      </div>
      <div class="biaoge">
        <form id="form" name="form" method="post" action="?action=delall">
          <?php 
		$pagenum = 12;
		$tablename = 'account';
		$akey=$_REQUEST['akey'];
		$w = " id is not null " ;	
		if($akey!=''){
		$w.=" and title like '%".$akey."%' ";
		}
		$w.=" order by id desc ";
		$total = mysql_fetch_array(mysql_query("select Count(*) from $tablename where $w "));
		$total = $total[0];
		if ($total!=0){
		$totalpage = ceil($total / $pagenum);
		if(!isset($_GET['page']) || !intval($_GET['page']) || $_GET['page'] > $totalpage){
			$page = 1;
		}
		else{
			$page = $_GET['page'];
		}
		$startnum=($page-1) * $pagenum;
		$sql = "select * from $tablename where $w limit $startnum, $pagenum";
		$result = mysql_query($sql);
?>
          <table width="832" border="0" cellspacing="1" cellpadding="1" bgcolor="#e34681">
            <tr height="30" bgcolor="#e34681" style="color:#FFF;">
              <td width="23"><input name="checkid" id="checkid" type="checkbox" onclick="checkall(this.checked);" /></td>
              <td width="92" align="left">account ID</td>
              <td width="114" align="left">Name</td>
              <td width="123" align="left">Price</td>
              <td width="114" align="left">Manage</td>
            </tr>
            <?php while($row = mysql_fetch_array($result)){?>
            <tr height="30" bgcolor="#FFFFFF">
              <td><input name="checkid[]" id="checkid[]" type="checkbox" value="<?php echo $row['id']?>" /></td>
              <td align="left"><?php echo $row['id']?></td>
              <td align="left"><?php echo $row['title']?></td>
              <td align="left"><?php echo $row['price']?></td>
              <td align="left" class="bj"><a href="javascript:show_window('account','id=<?php echo $row['id']?>')">Edit</a><a href="?action=del&id=<?php echo $row['id']?>">Delete</a></td>
            </tr>
            <?php }?>
          </table>
          <div style="text-align:center; padding-top:20px; padding-bottom:10px;"><?php echo  page($page, $totalpage, $pagenum, $total,$urlstring)?></div>
          <div class="pl"><a href="javascript:document.form.submit();">Bulk delete</a></div>
          <?php }else{?>
          <ul>
            <li style="padding:30px;">No information</li>
          </ul>
          <?php }?>
        </form>
      </div>
    </div>
  </div>
</div>
<?php include_once 'footer.php' ;?>